package com.ruoyi.smartcity.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.smartcity.traffic.domain.TrafficRoadState;
import com.ruoyi.smartcity.traffic.service.ITrafficRoadStateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 道路状态Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/smartcity/traffic/state")
public class TrafficRoadStateController extends BaseController
{
    @Autowired
    private ITrafficRoadStateService trafficRoadStateService;

    /**
     * 查询道路状态列表
     */
    @RequiresPermissions("traffic:state:list")
    @GetMapping("/list")
    public TableDataInfo list(TrafficRoadState trafficRoadState)
    {
        startPage();
        List<TrafficRoadState> list = trafficRoadStateService.selectTrafficRoadStateList(trafficRoadState);
        return getDataTable(list);
    }

    /**
     * 导出道路状态列表
     */
    @RequiresPermissions("traffic:state:export")
    @Log(title = "道路状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrafficRoadState trafficRoadState)
    {
        List<TrafficRoadState> list = trafficRoadStateService.selectTrafficRoadStateList(trafficRoadState);
        ExcelUtil<TrafficRoadState> util = new ExcelUtil<TrafficRoadState>(TrafficRoadState.class);
        util.exportExcel(response, list, "道路状态数据");
    }

    /**
     * 获取道路状态详细信息
     */
    @RequiresPermissions("traffic:state:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trafficRoadStateService.selectTrafficRoadStateById(id));
    }

    /**
     * 新增道路状态
     */
    @RequiresPermissions("traffic:state:add")
    @Log(title = "道路状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrafficRoadState trafficRoadState)
    {
        return toAjax(trafficRoadStateService.insertTrafficRoadState(trafficRoadState));
    }

    /**
     * 修改道路状态
     */
    @RequiresPermissions("traffic:state:edit")
    @Log(title = "道路状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrafficRoadState trafficRoadState)
    {
        return toAjax(trafficRoadStateService.updateTrafficRoadState(trafficRoadState));
    }

    /**
     * 删除道路状态
     */
    @RequiresPermissions("traffic:state:remove")
    @Log(title = "道路状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trafficRoadStateService.deleteTrafficRoadStateByIds(ids));
    }
}
